// 注册全局过滤器
import Vue from 'vue'
Vue.filter('dateFormat', function (originVal) {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})
Vue.filter('durationFormat', function (time) {
  const hh = parseInt(time / 3600000)
  time = time % 3600000
  const mm = parseInt(time / 60000)
  time = time % 60000
  const ss = parseInt(time / 1000)
  let str = ''
  if (hh) str += hh.toString().padStart(2, '0') + ':'
  if (mm) str += mm.toString().padStart(2, '0') + ':'
  if (ss) str += ss.toString().padStart(2, '0')
  return str
})

Vue.filter('dateYmdFormat', function (originVal) {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  return `${y}-${m}-${d}`
})
